package com.macro.cloud.controller;


import com.macro.cloud.domain.CommonResult;
import com.macro.cloud.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/storage")
public class StorageController {

    @Autowired
    private StorageService storageService;

    /**
     * 扣减库存
     * http://localhost:8181/storage/decrease?productId=1&count=2
     */
    @RequestMapping("/decrease")
    public CommonResult decrease(@RequestParam("productId") Long productId,@RequestParam("count") Integer count) {
        storageService.decrease(productId, count);
        
//        int i = 1/0;//如果执行异常，就不会去减库存
        
        return new CommonResult("扣减库存成功！",200);
    }
}
